<template>
  <div class="approval">
    <div v-show="isExistFirst">
      <el-card class="box-card" style="margin-bottom: 10px;">
        <div class="head-title">
          <div class="title">{{$t('approvalDetail.firstOrReviewOpinion')}}</div>
        </div>
        <div class="detail-info">
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.apprAccount')}}:</span>
            <span>{{apprOpinionObj.userName}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.elenuc')}}:</span>
            <span>{{apprOpinionObj.telStatus}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approval.result')}}:</span>
            <span>{{apprOpinionObj.status}}</span>
          </div>
          <div class="detail-info-item" v-show="apprOpinionObj.status === this.$t('approvalDetail.refuse')">
            <span>{{$t('approvalDetail.refuseReason')}}:</span>
            <span>{{apprOpinionObj.rejectReason}}</span>
          </div>
          <div class="detail-info-item" v-show="apprOpinionObj.status === this.$t('approvalDetail.derate')">
            <span>{{$t('approvalDetail.limit')}}:</span>
            <span>{{apprOpinionObj.approvedAmt}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.alternateContact')}}:</span>
            <span>{{apprOpinionObj.alternateContact}}</span>
          </div>
          <div class="detail-info-item">
            <span>SMS:</span>
            <span>{{apprOpinionObj.sms}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.remarks')}}:</span>
            <span>{{apprOpinionObj.checkOpinion}}</span>
          </div>
        </div>
      </el-card>
    </div>
    <div v-show="isExistEnd">
      <el-card class="box-card" style="margin-bottom: 10px;">
        <div class="head-title">
          <div class="title">{{$t('approvalDetail.endApprOpinion')}}</div>
        </div>
        <div class="detail-info">
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.apprAccount')}}:</span>
            <span>{{apprOpinionObj.checkFinishUser}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.finaljud')}}:</span>
            <span>{{apprOpinionObj.finalApprovalResult}}</span>
          </div>
          <div class="detail-info-item" v-show="apprOpinionObj.finalApprovalResult === this.$t('approvalDetail.refuse')">
            <span>{{$t('approvalDetail.refuseReason')}}:</span>
            <span>{{apprOpinionObj.endRejectReason}}</span>
          </div>
          <div class="detail-info-item" v-show="apprOpinionObj.finalApprovalResult === this.$t('approvalDetail.derate')">
            <span>{{$t('approvalDetail.limit')}}:</span>
            <span>{{apprOpinionObj.endApprovedAmt}}</span>
          </div>
          <div class="detail-info-item" v-show="apprOpinionObj.finalApprovalResult === this.$t('approvalDetail.refuseAndBlack')">
            <span>{{$t('approvalDetail.blackoutDesc')}}:</span>
            <span>{{apprOpinionObj.blackReason}}</span>
          </div>
          <div class="detail-info-item">
            <span>{{$t('approvalDetail.remarks')}}:</span>
            <span>{{apprOpinionObj.finalCheckOpinion}}</span>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getApprovalOpinion } from "api/AuditReport/apprAchiCount/index";
export default {
  data() {
    return {
      listObj: {},
      apprOpinionObj: {
        userName: "",
        telStatus: "",
        status: "",
        rejectReason: "",
        approvedAmt: "",
        alternateContact: "",
        sms: "",
        checkOpinion: "",
        checkFinishUser: "",
        finalApprovalResult: "",
        endRejectReason: "",
        endApprovedAmt: "",
        blackReason: "",
        finalCheckOpinion: ""
      },
      lanStatus: null,
      isExistFirst: false,
      isExistEnd: false
    };
  },
  computed: {
    ...mapGetters(["elements", "language", "apprAchiCountDetails"])
  },
  created() {
    this.getParamsDetail();
    if (this.language === "zh") {
      this.lanStatus = 1;
    } else if (this.language === "en") {
      this.lanStatus = 2;
    } else {
      this.lanStatus = 3;
    }
    // 审批结果回显
    let objs = {};
    objs.orderId = this.listObj.orderId;
    getApprovalOpinion(objs).then(res => {
      if (res.status === 200) {
        if (res.data.approvalResult === 1) {
          this.isExistFirst = false;
        } else {
          this.isExistFirst = true;
          if (res.data.telStatus === 1) {
            this.apprOpinionObj.telStatus = this.$t("approvalDetail.yes");
          } else if (res.data.telStatus === 2 || res.data.telStatus === '') {
            this.apprOpinionObj.telStatus = this.$t("approvalDetail.no");
          }
          if (res.data.approvalResult === 2) {
            this.apprOpinionObj.status = this.$t("approvalDetail.refuse");
            this.apprOpinionObj.rejectReason = res.data.rejectReason;
          } else if (res.data.approvalResult === 3) {
            this.apprOpinionObj.status = this.$t("approvalDetail.adopt");
          } else if (res.data.approvalResult === 4) {
            this.apprOpinionObj.status = this.$t("approvalDetail.derate");
            let re = /(?=(?!\b)(\d{3})+$)/g;
            let str = String(res.data.approvedAmt);
            res.data.approvedAmt = str.replace(re, ",");
            this.apprOpinionObj.approvedAmt = res.data.approvedAmt;
          }
          this.apprOpinionObj.userName = res.data.checkBaseUserName;
          this.apprOpinionObj.alternateContact = res.data.alternateContact;
          this.apprOpinionObj.sms = res.data.sms;
          this.apprOpinionObj.checkOpinion = res.data.checkOpinion;
        }
        if (res.data.finalApprovalResult === 5) {
          this.isExistEnd = false;
        } else {
          this.isExistEnd = true;
          if (res.data.finalApprovalResult === 1) {
            this.apprOpinionObj.finalApprovalResult = this.$t("approvalDetail.refuse");
            this.apprOpinionObj.endRejectReason = res.data.rejectFinalReason;
          } else if (res.data.finalApprovalResult === 2) {
            this.apprOpinionObj.finalApprovalResult = this.$t("approvalDetail.refuseAndBlack");
            this.apprOpinionObj.blackReason = res.data.blackReason;
          } else if (res.data.finalApprovalResult === 3) {
            this.apprOpinionObj.finalApprovalResult = this.$t("approvalDetail.adopt");
          } else if (res.data.finalApprovalResult === 4) {
            this.apprOpinionObj.finalApprovalResult = this.$t("approvalDetail.derate");
            let re = /(?=(?!\b)(\d{3})+$)/g;
            let str = String(res.data.approvedAmt);
            res.data.approvedAmt = str.replace(re, ",");
            this.apprOpinionObj.endApprovedAmt = res.data.approvedAmt;
          }
          this.apprOpinionObj.checkFinishUser = res.data.checkFinishUser;
          this.apprOpinionObj.finalCheckOpinion = res.data.finalCheckOpinion;
        }
      } else {
        this.$message({
          showClose: true,
          message: res.message,
          type: "warning"
        });
      }
    });
  },
  methods: {
    getParamsDetail() {
      this.listObj = this.apprAchiCountDetails;
    }
  }
};
</script>

<style scoped lang="scss">
input::-webkit-input-placeholder {
  font-size: 12px;
}
.approval-detail {
  width: 100%;
  height: 100%;
  padding-top: 10px;
  padding-left: 10px;
  padding-right: 10px;
  box-sizing: border-box;
  position: relative;
}
.title {
  line-height: 22px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.detail-info {
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  margin-left: 12px;
  margin-top: 5px;
  .detail-info-item {
    width: 50%;
    line-height: 25px;
    display: flex;
    padding-right: 20px;
    box-sizing: border-box;
    span:nth-child(1) {
      display: inline-block;
      width: 100px;
      text-align: left;
      margin-right: 5px;
      color: #616264;
    }
    span:nth-child(2) {
      flex: 1;
      color: #8a8a8c;
      display: inline-block;
      line-height: 25px;
    }
    .flag-btn {
      outline: none;
      border-width: 0;
      display: inline-block;
      font-size: 12px;
      width: 65px;
      height: 22px;
      line-height: 20px;
      text-align: center;
      margin-left: 15px;
      font-weight: normal;
      cursor: pointer;
    }
    button[disabled] {
      background: #c8c9cc !important;
      color: #fff !important;
      border: 1px solid #c8c9cc !important;
    }
  }
  .contact-list {
    width: 90%;
    margin: 10px 5%;
  }
}
.head-title {
  display: flex;
  line-height: 22px;
  .info {
    line-height: 28px;
    border: 1px solid #333;
    margin-left: 20px;
    font-size: 12px;
    border-radius: 5px;
    padding: 0 8px;
  }
}
</style>